# Contributor: rubicon <rubicon@mailo.com>
# Maintainer:
pkgname=ocaml-mirage-profile
_pkgname=mirage-profile
pkgver=0.9.1
pkgrel=2
pkgdesc="Collect runtime profiling information in CTF format"
url="https://github.com/mirage/mirage-profile"
arch="all !riscv64"  # limited by ocaml aport
license="BSD-2-clause"
depends="
	ocaml-runtime
	ocaml-cstruct
	ocaml-lwt
	ocaml-ocplib-endian
	ocaml-mtime
	"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-cstruct-dev
	ocaml-lwt-dev
	ocaml-ocplib-endian-dev
	ocaml-mtime-dev
	"
makedepends="$depends_dev dune ocaml"
options="!check"     # needs MProf.Trace.Control module
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.bz2::https://github.com/mirage/mirage-profile/releases/download/v$pkgver/mirage-profile-v$pkgver.tbz"
builddir="$srcdir/$_pkgname-v$pkgver"
_ocamldir=usr/lib/ocaml

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build \
		-p mirage-profile,mirage-profile-unix \
		--verbose
}

check() {
	dune runtest --verbose
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--docdir=/.omit \
		mirage-profile mirage-profile-unix
	rm -Rf "$pkgdir"/.omit
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; for path in $(find $_ocamldir \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.cmx' -o \
			-name '*.cmxa' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\))
	do
		amove "$path"
	done
}

sha512sums="
23cc4a2a62f5cc05b48d626bd6c8171a442fd46490da6810b1c507fcd7661c7fcd901d8328cddf687af4144136bf0d34b63f8484e32550077ab63d23e6eaea2b  ocaml-mirage-profile-0.9.1.tar.bz2
"
